package com.hy.myapp.util;

import java.security.MessageDigest;

import org.apache.tomcat.util.codec.binary.Base64;

public class CryptUtil {
	/**
	 * 取得MD5摘要
	 * @param plainTxt
	 * @return
	 */
	public static String getMD5Digest(String plainTxt) {
		try {
            // MD5,SHA，SHA-256，SHA-384，SHA-512
            final String ALGORITHM="MD5";
            MessageDigest md=MessageDigest.getInstance(ALGORITHM);
            byte[] digests=md.digest(plainTxt.getBytes());
            
            String digestTxt=Base64.encodeBase64String(digests);
            return digestTxt;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
	}
}
